package com.sz.biz.logistics.ord.service.impl;

import com.sz.biz.common.constants.CommCodes;
import com.sz.biz.common.constants.ErrorCodes;
import com.sz.biz.csr.entity.CsrWorkOrderSchema;
import com.sz.biz.csr.service.CsrWorkOrderSchemaService;
import com.sz.biz.csr.service.impl.CsrWorkOrderSchemaServiceImpl;
import com.sz.biz.logistics.billing.dto.OrderCalcResult;
import com.sz.biz.logistics.constants.QuotationConstants;
import com.sz.biz.logistics.core.entity.ProductServiceRel;
import com.sz.biz.logistics.core.service.ServiceService;
import com.sz.biz.logistics.ord.constants.OrderConstants;
import com.sz.biz.logistics.ord.dto.OrdOrderFeeDto;
import com.sz.biz.logistics.ord.dto.OrdOrderOptionService;
import com.sz.biz.logistics.ord.entity.*;
import com.sz.biz.logistics.ord.enums.TrackMessageToServiceEnum;
import com.sz.biz.logistics.ord.service.*;
import com.sz.biz.pay.constants.PayStatus;
import com.sz.common.base.dao.ParamData;
import com.sz.common.base.exception.BizException;
import com.sz.common.base.exception.Exceptions;
import com.sz.common.base.service.AbstractService;
import com.sz.common.base.utils.CollectionUtils;
import com.sz.common.base.utils.EntityUtils;
import com.sz.common.base.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.util.*;

/**
 * Function: 产品订单的附加服务 <br>
 * Author: hpeng.wang. <br>
 * Date: 2017-03-31 13:52:00.
 */
@Service("ordOrderFeeService")
public class OrdOrderFeeServiceImpl extends AbstractService implements OrdOrderFeeService {
    @Autowired
    private OrdOrderServiceAssignService orderServiceAssignService;
    @Autowired
    private OrdOrderService orderService;
    @Autowired
    private OrdTrackingMessageService trackingMessageService;
    @Autowired
    private OrdOrderTrackingService orderTrackingService;

    @Autowired
    private OrderCalcJobService orderCalcJobService;

    @Autowired
    private ServiceService serviceService;
    @Autowired
    private CsrWorkOrderSchemaService csrWorkOrderSchemaService;

    @Override
    protected String getMapperNamespace() {
        return "com.sz.biz.logistics.ord.OrdOrderFeeMapper";
    }

    /**
     * 新增
     *
     * @param entry 新增的实体
     * @return 新增是否成功
     */
    @Override
    public void save(OrdOrderFee entry) {
        this.batchSave(Arrays.asList(entry));
    }

    @Override
    public void batchSave(List<OrdOrderFee> ordOrderFeeList) {
        if (!CollectionUtils.isEmpty(ordOrderFeeList)) {
            dao.batchInsert(getSqlName("insertSelective"), ordOrderFeeList);
            //保存操作日志
            //Map<String, Object> dataBackup = new HashMap<>();
            //dataBackup.put("ADD_ORDER_ADDITION", ordOrderFeeList);
            //PrincipalLogUtils.addOperationLog(ModuleNames.ORD, ModuleNames.ORD_ORDER_FEE, UserActions.ADD, "添加订单费用", dataBackup);
        }
    }


    @Override
    public void deleteByOrderNo(String orderNo) {
        if (StringUtils.hasLength(orderNo)) {
            dao.delete(getSqlName("deleteByOrderNo"), orderNo);
        }
    }


    /**
     * 更新实体
     *
     * @param entry 更新的实体
     * @return 新增是否成功
     */
    @Override
    public int update(OrdOrderFee entry) {
        int count = this.batchUpdate(Arrays.asList(entry));
        return count;
    }

    /**
     * 根据订单号、费用、费用单位，创建订单费用信息(ord_order_fee)
     *
     * @param orderNo      订单号
     * @param fee          费用
     * @param currencyCode 费用的单位
     */
    @Override
    public void saveOrUpdate(String orderNo, BigDecimal fee, String currencyCode) {
        OrdOrderFee orderFee = this.findByOrderNo(orderNo);//查询数据是否存在
        OrdOrder order = orderService.findByOrderNo(orderNo);
        if (ObjectUtils.isEmpty(order)) {
            throw Exceptions.bizException(ErrorCodes.ERROR_COMMON, "订单未找到");
        }
        if (ObjectUtils.isEmpty(orderFee)) {
            orderFee = new OrdOrderFee();
            orderFee.setOrderNo(orderNo);
        }

        if (OrderStatus.RECEGOOD.compareTo(order.getOrderStatus()) > 0) {
            orderFee.setEstimateFee(fee);
            orderFee.setEstimateCurrencyCode(currencyCode);
        } else {
            orderFee.setActualFee(fee);
            orderFee.setActualCurrencyCode(currencyCode);
        }

        if (orderFee.getId() == null || orderFee.getId() <= 0) {//不存在
            this.save(orderFee);
        } else {//存在
            this.update(orderFee);
        }
    }

    /**
     * 批量修改实体
     *
     * @param list
     */
    @Override
    public int batchUpdate(List<OrdOrderFee> list) {
        int count = 0;
        if (!CollectionUtils.isEmpty(list)) {
            count = dao.batchUpdate(getSqlName("updateByOrderNoSelective"), list);
        }
        return count;
    }

    /**
     * 根据主键Id查询单个实体
     *
     * @param id 主键id
     * @return 查询出来的实体对象
     */
    @Override
    public OrdOrderFee findById(Integer id) {
        return null;
    }

    /**
     * 根据id集合查询实体
     *
     * @param ids
     * @return
     */
    @Override
    public List<OrdOrderFee> findByIds(List<Integer> ids) {
        return null;
    }


    @Override
    public OrdOrderFee findByOrderNo(String orderNo) {
        OrdOrderFee ordOrderFee = null;
        List<OrdOrderFee> orderFees = this.findByOrderNos(Arrays.asList(orderNo));
        if (!CollectionUtils.isEmpty(orderFees)) {
            if (orderFees.size() == 1) {
                ordOrderFee = orderFees.get(0);
            } else {
                throw Exceptions.bizException(ErrorCodes.ERROR_COMMON, "订单费用查询出多条数据");
            }
        }
        return ordOrderFee;
    }

    /**
     * 根据订单编号查询对应的订单费用列表
     *
     * @param orderNoList 订单编号列表
     * @return 订单费用列表
     */
    @Override
    public List<OrdOrderFee> findByOrderNos(List<String> orderNoList) {
        if (orderNoList == null || orderNoList.size() <= 0) {
            throw Exceptions.bizException(ErrorCodes.ERROR_ARGUMENT_EMPTY, orderNoList);
        }
        ParamData pd = new ParamData();
        pd.put("orderNos", orderNoList);
        List<OrdOrderFee> list = dao.findForList(getSqlName("findByOrderNos"), pd, OrdOrderFee.class);
        return list;
    }

    /**
     * 根据orderNoList获取订单费用的dto集合
     *
     * @param orderNo
     * @return
     */
    @Override
    public OrdOrderFeeDto findDtoByOrderNo(String orderNo) {
        OrdOrderFeeDto ordOrderFeeDto = null;
        OrdOrderFee ordOrderFee = this.findByOrderNo(orderNo);
        if (!ObjectUtils.isEmpty(ordOrderFee)) {
            ordOrderFeeDto = new OrdOrderFeeDto();
            EntityUtils.copyPropertiesIgnoreNull(ordOrderFee, ordOrderFeeDto);
        }
        return ordOrderFeeDto;
    }

    /**
     * 根据订单号集合，批量获取订单费用
     *
     * @param orderNos
     * @return
     */
    @Override
    public Map<String, OrdOrderFeeDto> findMapDtosByOrderNos(List<String> orderNos) {
        Map<String, OrdOrderFeeDto> orderFeeDtoMap = new HashMap<>();
        if (!CollectionUtils.isEmpty(orderNos)) {
            List<OrdOrderFee> orderFeeList = this.findByOrderNos(orderNos);
            for (OrdOrderFee orderFee : orderFeeList) {
                OrdOrderFeeDto ordOrderFeeDto = new OrdOrderFeeDto();
                EntityUtils.copyPropertiesIgnoreNull(orderFee, ordOrderFeeDto);
                orderFeeDtoMap.put(ordOrderFeeDto.getOrderNo(), ordOrderFeeDto);
            }
        }
        return orderFeeDtoMap;
    }

    @Override
    public void submitBillByAccept(String orderNo) {
        OrdOrder order = orderService.findByOrderNo(orderNo);
        OrdServiceAssign serviceAssign = this.orderServiceAssign(orderNo, order);
        List<OrdOrderOptionService> optionServices = orderServiceAssignService.findOrderServiceByOrderNo(orderNo, null);
        if (!ObjectUtils.isEmpty(serviceAssign)) {
            this.saveChannelNo(orderNo,optionServices);
            if (serviceAssign.getIsAssignOk()) {

                this.orderCalcFee(orderNo);
            } else {
                String content = this.assembleCsrWorkContent(serviceAssign.getCalcMsg(), optionServices, order.getWaybillNo());
                String title = "订单多服务分派异常";
                int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_AFFECT_WAYBILL;
                csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
            }

            //当订单的状态为已受理时，给第一个供应商发揽收的物流消息
            OrdOrderOptionService optionService = optionServices.get(0);
            if (OrderStatus.ACCEPT == order.getOrderStatus()) {
                if (!ObjectUtils.isEmpty(optionService) && optionService.isAssignSign()) {
                    this.sendTrackingByLs(order, optionService);
                }
            }
        }

    }

    /**
     * 保存渠道单号
     *
     * @param orderNo        订单号
     * @param optionServices 订单选择的服务
     */
    public void saveChannelNo(String orderNo, List<OrdOrderOptionService> optionServices) {
        if (CollectionUtils.isEmpty(optionServices)) {
            optionServices = orderServiceAssignService.findOrderServiceByOrderNo(orderNo);
        }
        if (!CollectionUtils.isEmpty(optionServices)) {
            OrdOrder order = new OrdOrder();
            order.setOrderNo(orderNo);
            List<OrdOrderOptionService> optionServiceList = new ArrayList<>(optionServices);
            Collections.reverse(optionServiceList);
            String channelNo = "";
            for (OrdOrderOptionService optionService : optionServiceList) {
                if (optionService.isAssignSign() && !StringUtils.isEmpty(optionService.getServiceChannelNo())) {
                    channelNo = optionService.getServiceChannelNo();
                    break;
                }
            }
            if (!StringUtils.isEmpty(channelNo)) {
                order.setChannelNo(channelNo);
                orderService.update(order);
            }
        }
    }

    @Override
    public void submitBillByReceGood(String orderNo) {
        OrdOrder order = orderService.findByOrderNo(orderNo);
        OrdServiceAssign serviceAssign = this.orderServiceAssign(orderNo, order);
        List<OrdOrderOptionService> optionServices = orderServiceAssignService.findOrderServiceByOrderNo(orderNo);
        if (!ObjectUtils.isEmpty(serviceAssign)) {
            this.saveChannelNo(orderNo,optionServices);
            if (serviceAssign.getIsAssignOk()) {
                boolean bOk = this.orderCalcFee(orderNo);
                if (!bOk) {
                    String title = "订单计费出错";
                    String content = "订单计费出错";
                    int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_WAYBILL;
                    csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
                }
            } else {
                String content = this.assembleCsrWorkContent(serviceAssign.getCalcMsg(), optionServices, order.getWaybillNo());
                String title = "订单多服务分派异常";
                int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_AFFECT_WAYBILL;
                csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
            }
        }
    }

    @Override
    public boolean submitBillByTransport(String orderNo) {
        boolean isSucceed = false;
        OrdOrder order = orderService.findByOrderNo(orderNo);
        OrdServiceAssign serviceAssign = this.orderServiceAssign(orderNo, order);
        List<OrdOrderOptionService> optionServices = orderServiceAssignService.findOrderServiceByOrderNo(orderNo);
        if (!ObjectUtils.isEmpty(serviceAssign)) {
            this.saveChannelNo(orderNo,optionServices);
            if (serviceAssign.getIsAssignOk()) {
                boolean bOk = this.orderCalcFee(orderNo);
                if (!bOk) {
                    String title = "订单计费出错";
                    String content = "订单计费出错";
                    int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_AFFECT_WAYBILL;
                    csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
                } else {
                    //如果本次重新分派服务，并计算费用成功后，当前是有阻塞性工单，订单未支付,也不允许出库,这时对订单的状态也不进行更改
                    if (csrWorkOrderSchemaService.isBlockByOrderNo(order.getOrderNo()) || order.getPayStatus() != PayStatus.PAID) {
                        //如果是因为订单未支付引起的阻塞，那么要创建阻塞性工单
                        if (order.getPayStatus() != PayStatus.PAID) {
                            String title = "订单未支付";
                            String content = "订单未支付";
                            int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_AFFECT_WAYBILL;
                            csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
                        }
                    } else {
                        isSucceed = true;
                    }


                }
            } else {
                String content = this.assembleCsrWorkContent(serviceAssign.getCalcMsg(), optionServices, order.getWaybillNo());
                String title = "订单多服务分派异常";
                int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_AFFECT_WAYBILL;
                csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
            }
        }
        return isSucceed;
    }

    /**
     * 当订单处于运输中之后的状态，对订单的修改也要触发物多服务分派、计费
     *
     * @param orderNo 订单号
     * @return
     */
    @Override
    public boolean submitBillByTransportAfter(String orderNo) {
        boolean isSucceed = false;
        OrdOrder order = orderService.findByOrderNo(orderNo);
        OrdServiceAssign serviceAssign = this.orderServiceAssign(orderNo, order);
        List<OrdOrderOptionService> optionServices = orderServiceAssignService.findOrderServiceByOrderNo(orderNo, null);
        if (!ObjectUtils.isEmpty(serviceAssign)) {
            this.saveChannelNo(orderNo,optionServices);
            if (serviceAssign.getIsAssignOk()) {
                boolean bOk = this.orderCalcFee(orderNo);
                if (!bOk) {
                    //当订单状态在运输中之后，多服务分派成功，计费失败，创建工单，但不阻塞
                    String title = "订单多服务分派成功，但订单计费出错";
                    String content = "订单多服务分派成功，但订单计费出错";
                    int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_WAYBILL;
                    csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
                } else {
                    //当订单状态在运输中之后，多服务分派成功，计费成功，创建工单，并且不阻塞
                    String title = "订单多服务分派成功，订单成功！";
                    String content = "订单多服务分派成功，订单成功！";
                    int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_WAYBILL;
                    csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
                    isSucceed = true;
                }
            } else {
                //当订单状态在运输中之后，多服务分派失败，创建工单，但不阻塞
                String content = this.assembleCsrWorkContent(serviceAssign.getCalcMsg(), optionServices, order.getWaybillNo());
                String title = "订单多服务分派异常";
                int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_WAYBILL;
                csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
            }
        }
        return isSucceed;
    }

    public boolean submitBill(String orderNo) {
        boolean bOk = false;
        OrdOrder order = orderService.findByOrderNo(orderNo);
        OrderStatus orderStatus = order.getOrderStatus();
        //如果订单已经发送过运输中的物流，那么就可调用 submitBillByTransport
        if (OrderConstants.OrderTransportStatus.ORDER_TRANSPORT == order.getTransportStatus()) {
            orderStatus = OrderStatus.TRANSPORT;
        }

        switch (orderStatus) {
            case COMMITED:
            case ACCEPT:
                this.submitBillByAccept(orderNo);
                break;
            case RECEGOOD:
                this.submitBillByReceGood(orderNo);
                break;
            case TRANSPORT:
                bOk = this.submitBillByTransport(orderNo);
                break;
            case DISPACTCHING:
            case RECEIVED:
                bOk = this.submitBillByTransportAfter(orderNo);
                break;
        }
        return bOk;
    }

    public boolean submitB1ill(String orderNo, boolean isTracking) {
        boolean isOk = true;
        OrdOrder order = orderService.findByOrderNo(orderNo);
        boolean bOk = this.orderServiceAssign(orderNo);
        if (bOk) {
            bOk = this.orderCalcFee(orderNo);
            //当已受理时，计费失败后，不做任何操作
            if (!bOk && order.getOrderStatus() != OrderStatus.ACCEPT) {
                String title = "订单计费出错";
                String content = "订单计费出错";
                //当订单的状态为已收货时，创建的计费出错工单是非阻塞的，否则创建的工单是阻塞性工单
                int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_WAYBILL;
                //已收货时，计费失败，创建非阻塞性工单
                if (order.getOrderStatus() == OrderStatus.RECEGOOD) {
                    type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_AFFECT_WAYBILL;
                }
                csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
            } else if (bOk) {
                //当订单状态为运输中时，这时订单未支付，要创建阻塞性工单
                if (PayStatus.PAID != order.getPayStatus() && order.getOrderStatus() == OrderStatus.TRANSPORT) {
                    String title = "订单未支付";
                    String content = "订单未支付";
                    int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_AFFECT_WAYBILL;
                    csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
                    //当订单状态为运输中时，并且订单已经支付，这时就可以让供应商出库了。
                    isOk = false;
                } else if (PayStatus.PAID == order.getPayStatus()) {


                    List<CsrWorkOrderSchema> workOrderSchemaList = csrWorkOrderSchemaService.queryBlockByOrderNo(orderNo);
                    if (!CollectionUtils.isEmpty(workOrderSchemaList) && isTracking) {
                        return false;
                    } else if (!CollectionUtils.isEmpty(workOrderSchemaList) && !isTracking) {
                        orderService.sendOutgoingMessage(orderNo);
                    }
                }
                //当订单状态大于运输中后，对订单的任何修改都要添加工单，失败情况上面已经处理了，所以这里只处理成功的情况
                if (order.getOrderStatus().compareTo(OrderStatus.TRANSPORT) > 0 && bOk) {
                    String title;
                    String content;
                    title = "计费发生变化";
                    content = "计费发生变化";
                    csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_WAYBILL);
                }
            }

        }
        return isOk;
    }

    private boolean orderCalcFee(String orderNo) throws BizException {
        boolean bOk = false;
        OrderCalcResult calcResult = orderCalcJobService.calcOrdOrder(orderNo, QuotationConstants.Type.SELLING);
        if (calcResult!=null && calcResult.isSuccessed() && !StringUtils.isEmpty(calcResult.getCurrency())) {
            bOk = calcResult.isSuccessed();
            this.saveOrUpdate(orderNo, calcResult.getAmount(), calcResult.getCurrency());
        }
        return bOk;
    }

    /**
     * 订单的多服务分派，如果多服务分派失败，则创建阻塞性工单，如果订单的状态为已揽收，则要给第一个供应商发物流消息
     *
     * @param orderNo 订单号
     */
    @Override
    public boolean orderServiceAssign(String orderNo) {
        boolean bOk = false;
        //1、得到订单的信息
        OrdOrder order = orderService.findByOrderNo(orderNo);
        this.orderServiceAssign(orderNo, order);

        //3、查询多服务分派的信息
        OrdServiceAssign serviceAssign = orderServiceAssignService.findByOrderNo(orderNo);
        if (!ObjectUtils.isEmpty(serviceAssign)) {
            bOk = serviceAssign.getIsAssignOk();
        }
        List<OrdOrderOptionService> optionServices = orderServiceAssignService.findOrderServiceByOrderNo(orderNo, null);

        //4、当订单的状态为已受理时，给第一个供应商发揽收的物流消息
        OrdOrderOptionService optionService = optionServices.get(0);
        if (OrderStatus.ACCEPT == order.getOrderStatus()) {
            if (!ObjectUtils.isEmpty(optionService) && optionService.isAssignSign()) {
                this.sendTrackingByLs(order, optionService);
            }
        }
        //5、多服务分派失败时，创建阻塞性工单
        if (ObjectUtils.isEmpty(serviceAssign) || !bOk) {
            String content = this.assembleCsrWorkContent(serviceAssign.getCalcMsg(), optionServices, order.getWaybillNo());
            String title = "订单多服务分派异常";
            int type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_AFFECT_WAYBILL;

            //当订单的状态为运输中后，多服务分派失败，创建工单，非阻塞
            if (order.getOrderStatus().compareTo(OrderStatus.TRANSPORT) > 0) {
                type = CsrWorkOrderSchemaServiceImpl.WORK_ORDER_SCHEMA_TYPE_WAYBILL;
            }
            csrWorkOrderSchemaService.saveCsrWorkOrderSchemaByOrd(order, title, content, type);
        }
        return bOk;
    }

    private OrdServiceAssign orderServiceAssign(String orderNo, OrdOrder order) {
        ProductServiceRel productServiceRel = trackingMessageService
                .findCurServiceByTracking(order.getWaybillNo(), order.getProductUid(), order.getCreateTime());
        String serviceTypeCode = "";
        if (!ObjectUtils.isEmpty(productServiceRel)) {
            serviceTypeCode = productServiceRel.getServiceTypeCode();
        }

        //2、进行服务分派
        logger.info("开始分派订单的服务：" + orderNo);
        orderServiceAssignService.calc(orderNo, serviceTypeCode);
        logger.info("结束分派订单的服务：" + orderNo);

        //3、查询多服务分派的信息
        OrdServiceAssign serviceAssign = orderServiceAssignService.findByOrderNo(orderNo);
        return serviceAssign;
    }

    private void sendTrackingByLs(OrdOrder order, OrdOrderOptionService optionService) {
        if (optionService.isAssignSign()) {
            com.sz.biz.logistics.core.entity.Service service = serviceService.findById(optionService.getServiceId());
            OrdTrackingMessage trackingMessage = orderTrackingService.orderTrackingToService(order.getWaybillNo(), TrackMessageToServiceEnum.PLACE_TRADE_ORDER.getCode(), CommCodes.TRACKING_TYPE_SYSTEM_AUTO, service.getUid(), service.getSupplierId());
            trackingMessageService.save(trackingMessage);
        }
    }


    /**
     * 根据服务分派的信息，创建工单的内容
     *
     * @param calcMsg        分派的详细信息
     * @param optionServices 分派的服务信息
     * @param waybillNo      运单号
     * @return 工单的内容信息
     */
    private String assembleCsrWorkContent(String calcMsg, List<OrdOrderOptionService> optionServices, String waybillNo) {
        StringBuffer sb = new StringBuffer();
        sb.append("运单：" + waybillNo).append(",服务类型:");
        for (OrdOrderOptionService service : optionServices) {
            if (!service.isAssignSign()) {
                sb.append(service.getServiceTypeCode()).append(",");
            }
        }
        sb.append(" 分派失败。\r\n").append(calcMsg).toString();
        return sb.toString();
    }


    @Override
    public Map<String, List<String>> findMapByOrderNos(List<String> orderNoList) {
        return null;
    }


}
